package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.po.MRecordSeriesRechargeDetailPO;
import com.yiyuan.app.mapper.MRecordSeriesRechargeDetailMapper;
import org.springframework.stereotype.Repository;

@Repository
public class MRecordSeriesRechargeDetailDAO extends BaseDAO<MRecordSeriesRechargeDetailMapper, MRecordSeriesRechargeDetailPO> {

    public MRecordSeriesRechargeDetailPO findAlreadyRecharge(Long userId, Long recordRechargeId, Integer rechargeDay) {
        LambdaQueryWrapper<MRecordSeriesRechargeDetailPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRecordSeriesRechargeDetailPO::getUserId, userId);
        queryWrapper.eq(MRecordSeriesRechargeDetailPO::getRecordRechargeId, recordRechargeId);
        queryWrapper.eq(MRecordSeriesRechargeDetailPO::getRechargeDay, rechargeDay);
        return getBaseMapper().selectOne(queryWrapper);
    }

    public MRecordSeriesRechargeDetailPO findLatestAlreadyRecharge(Long userId, Long recordRechargeId) {
        LambdaQueryWrapper<MRecordSeriesRechargeDetailPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRecordSeriesRechargeDetailPO::getUserId, userId);
        queryWrapper.eq(MRecordSeriesRechargeDetailPO::getRecordRechargeId, recordRechargeId);
        queryWrapper.orderByDesc(MRecordSeriesRechargeDetailPO::getRechargeDay);
        queryWrapper.last("limit 0,1");
        return getBaseMapper().selectOne(queryWrapper);
    }


    public MRecordSeriesRechargeDetailPO findOne(Long userId, Long recordRechargeId, Integer day) {
        LambdaQueryWrapper<MRecordSeriesRechargeDetailPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRecordSeriesRechargeDetailPO::getUserId, userId);
        queryWrapper.eq(MRecordSeriesRechargeDetailPO::getRecordRechargeId, recordRechargeId);
        queryWrapper.eq(MRecordSeriesRechargeDetailPO::getRechargeDay, day);
        return getBaseMapper().selectOne(queryWrapper);
    }
}
